import React from 'react';
import * as asyncLoad from '../util/asyncLoad';
import { workflowPublicFiles } from '../constants/fileConfig';
import Loading from './Loading';
import * as RigthBtn from '../util/rightBtn';
import {showAuthDetail,closeAuthDetail} from "../util/secondAuthUtil";

export default class LogList extends React.Component{
    constructor(){
        super();
        this.state = {
            hasLoad: false,
            store:null,
            store1:null
        };
    }
    componentDidMount(){
        const init = () =>{
          const { commonParam } = this.props;
          const { SecondAuthStore, WfFormLogListStore } = window.weaWorkflowPublic;   
          const store = new WfFormLogListStore();
          store.initLog(commonParam);
          this.setState({hasLoad: true, store:store, store1: SecondAuthStore});
        }
        asyncLoad.asyncLoadModule('workflowPublic', workflowPublicFiles, init);
    }

    componentWillReceiveProps(nextProps) {
        const {isRelaodLogList = false,reloadLogListParams ={}} = nextProps;
        if(isRelaodLogList) {
          const {store} = this.state;
          store.updateLogParams(reloadLogListParams,true);
        }
    }

    render(){
        const { setTabKey } = this.props;
        const { hasLoad,store, store1 } = this.state;
        if(hasLoad){
            const { WfFormLogListCom } = window.weaWorkflowPublic;
            let {forward,controlVariableMap,commonParam,variableMap } = this.props;
            const {isOpenCommunication} = commonParam
            if(commonParam.belongTest){
                forward = '0';
            }
            store1.setCommonParam(commonParam);

            return (
                <WfFormLogListCom ecId={`${this && this.props && this.props.ecId || ''}_WfFormLogListCom@o3006d`}
                    isOpenCommunication={isOpenCommunication}
                    setTabKey={setTabKey} 
                    logListStore={store}
                    controlVariableMap={controlVariableMap}
                    variableMap={variableMap}
                    forward={forward}
                    forwardEvent={RigthBtn.doReviewE9}
                    showAuthDetail={showAuthDetail}
                    closeAuthDetail={closeAuthDetail}
                    secondAuthStore={store1}/>
            )
        }else{
            return (<Loading ecId={`${this && this.props && this.props.ecId || ''}_Loading@iy0jv7`} />);
        }
    }
}